# coding=utf-8
"""
conf class
Author: kaspar
Date: 2022-03-31
"""
import threading
import configparser

class Config(object):
    """
    conf class
    """
    conf_instance = None
    conf_mutex = threading.Lock()

    def __init__(self):
        """
         init function
        """
        self._conf_file = './conf/config.conf'
        self._conf_obj = configparser.ConfigParser()
        self._conf_obj.read(self._conf_file, "UTF-8")

    @staticmethod
    def get_instance():
        """
        get conf instance
        """
        if (Config.conf_instance is None):
            Config.conf_mutex.acquire()
            if (Config.conf_instance is None):
                Config.conf_instance = Config()
            Config.conf_mutex.release()
        return Config.conf_instance._conf_obj

    @staticmethod
    def get_conf(section, key):
        """
        get conf key value
        """
        return Config.get_instance().get(section, key)

if __name__ == '__main__':
    # print(Config.get_conf("db_mongo", "mongo_address"))
    print( Config.get_conf('server', 'port'))
